package com.xncoding.netty.server.tcp;

import com.xncoding.netty.coder.tcp.ByteDecoder;
import com.xncoding.netty.handler.tcp.byteTcpServerHandler;
import com.xncoding.netty.server.NettyServiceTemplate;
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.FixedLengthFrameDecoder;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;

public class ByteTcpServer extends NettyServiceTemplate {
	private int port = 8088;
	private String name = "String Server";

	// SpringBeanService springBeanService;
	public ByteTcpServer() {
	}
	public ByteTcpServer(int port) {
		this.port = port;
	}

	// 可以启动server时将spring的bean传递进来。
	// public StringTcpServerTest(int port, SpringBeanService springBeanService)
	// {
	// this.port = port;
	// this.springBeanService = springBeanService;
	// }

	@Override
	protected ChannelHandler[] createHandlers() {
		return new ChannelHandler[] { 
//				new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()), //分隔符解码器,定义了以("\n")为结尾分割的 解码器
//				new FixedLengthFrameDecoder(86),
				new ByteDecoder(),
				new byteTcpServerHandler()
		};
	}

	@Override
	public int getPort() {
		return port;
	}

	@Override
	public String getName() {
		return name;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setName(String name) {
		this.name = name;
	}

}
